#include "PrecompiledHeader_Engineer.h"
#include "CSplashscreen.h"

/*--------------------------------------------------------------------------*/

CSplashscreen::CSplashscreen() :
	EngMod("CSplashscreen", 0),
	IGameMode("splashscreen")
{
	this->AddRenderTask(CContext::getInstance()->GetContext("d2d"),
	                    CMaterial::getInstance()->GetNullMaterial(),
	                    CCamera::getInstance()->GetCamera("cam2d"),
	                    0,
	                    vl::Render::UserInterface);

	CShell::getInstance()->RegisterLuaFunction("splashscreen", sh::splashscreen);
}

/*--------------------------------------------------------------------------*/

CSplashscreen::~CSplashscreen()
{

}

/*--------------------------------------------------------------------------*/

void CSplashscreen::OnInit()
{
	CResources::getInstance()->Get("splashscreen", &this->m_splashscreen);
}

/*--------------------------------------------------------------------------*/

void CSplashscreen::OnCalc(unsigned int threadId)
{
	this->BindRenderTasks();
}

/*--------------------------------------------------------------------------*/

void CSplashscreen::OnRender(const unsigned int i, vl::Render::LevelOfDetail quality)
{
	switch (i)
	{
	case 0:
	{
		OpenGL::DrawRectangle(glm::vec2(), CSettings::getInstance()->m_resolutionf, vl::Black);

		if (this->m_splashscreen != NULL)
		{
			//glm::vec2 margin = (CSettings::getInstance()->m_resolutionf - glm::vec2(this->m_splashscreen->GetSize().x, this->m_splashscreen->GetSize().y)) * 0.5f;
			OpenGL::DrawRectangle(glm::vec2(), CSettings::getInstance()->m_resolutionf, vl::White, this->m_splashscreen);
		}

		break;
	}
	}
}

/*--------------------------------------------------------------------------*/

void CSplashscreen::OnStart()
{
	//CShell::getInstance()->Execute("script start_game");
}

/*--------------------------------------------------------------------------*/

void CSplashscreen::OnStop()
{

}

/*--------------------------------------------------------------------------*/

void CSplashscreen::SetSplashTexture(Texture* t)
{
	this->m_splashscreen = t;
}

/*--------------------------------------------------------------------------*/

void CSplashscreen::SetSplashTexture(const std::string& name)
{
	Texture* t = NULL;
	CResources::getInstance()->Get(name, &t);

	this->SetSplashTexture(t);
}

/*--------------------------------------------------------------------------*/

void sh::splashscreen(const std::string& name)
{
	CSplashscreen::getInstance()->SetSplashTexture(name);
}

/*--------------------------------------------------------------------------*/
